<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2024/10/7
  Time: 17:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="use.Message" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
    String addMessageInfo = (String) session.getAttribute("addMessageInfo");
    Boolean ifLogin = (Boolean) session.getAttribute("ifLogin");

    if (ifLogin == null || !ifLogin) {
        request.setAttribute("Info", "未登录，请登录！");
        request.getRequestDispatcher("login.jsp").forward(request, response);
        return; // 确保不继续执行后续代码
    }
%>

<html>
<head>
    <title>我的留言板</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        table {
            width: 60%;
            border-collapse: collapse;
        }
        table, th, td {
            border: 1px solid black;
        }
        th, td {
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
        form {
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<% if (addMessageInfo != null) {
    out.println("<p>" + addMessageInfo + "</p>");
} %>
<br>
<h3>我的留言：</h3>
<p> <a href="addMessage.jsp">添加留言</a> </p>

<%  List<Message> messages = (List<Message>) session.getAttribute("messages");
    if (messages != null && !messages.isEmpty()) {
%>
<table>
    <%
        for (Message message : messages) {
    %>
    <tr>
        <td>
            <form action="showServlet" method="post">
                <input type="hidden" name="messageId" value="<%= message.getId() %>"/>
                <span style="font-weight:bold;"><%= message.getTitle() %></span>
                <input type="submit" value="查看详情">
            </form>
        </td>
    </tr>
    <%
        }
    %>
</table>
<%
    } else {
        out.println("<p>暂无留言</p>");
    }
%>
</body>
</html>